<?php

if (isset($_POST['submit_invest']))
{
	$an = stripslashes(@$_POST['title']);

	$a_fc = stripslashes(@$_POST['fontcolor']);
	$a_fn = stripslashes(@$_POST['fontname']);
	$a_fa = '0';//stripslashes(@$_POST['fontangle']);
	$a_fs = stripslashes(@$_POST['fontsize']);

	$a_ol = stripslashes(@$_POST['t_offl']);
	$a_ot = stripslashes(@$_POST['t_offt']);
	$a_bw = stripslashes(@$_POST['t_boxw']);
	$a_if = @$_FILES['imageurl']['name'];
	$a_ift = @$_FILES['imageurl']['tmp_name'];

	/*@session_start();
	$access_token = $_SESSION['access_token'];
	
	$suser = $access_token['user_id'];*/

	//need to write to client's file
	$topdir = "./paths/".$an.".php";

	$fh = fopen($topdir, 'w');
	
	fwrite($fh, "<?php\n\r\$defaultcolor = '$a_fc';\n\r\$defaultfont = '$a_fn';\n\r\$defaultangle = '0';\n\r\$defaultsize = '$a_fs';\n\r\$pathinfo = array(array(\$defaultsize, \$defaultangle, '$a_ol,$a_bw', $a_ot, \$defaultcolor, \$defaultfont),);\n\r?>");
	fclose($fh);
	
	
	$topdir = "./img/".$an.".jpg";
	$img = imagecreatefromstring(file_get_contents($a_ift));
	
	imagejpeg($img, $topdir);
	imagedestroy($img);
	header("Location:index.php");
}
else
{
$content = <<<EOF
<form method="post" action="newimage.php" enctype="multipart/form-data">
<input type="hidden" name="suser" value="<?php echo $suser; ?>" />
<table>
<tr><td>Name:</td></tr>
<tr><td><input type = "text" name="title" value="" /></td></tr>
<tr><td>Font color:</td></tr>
<tr><td><input type = "text" name="fontcolor" value="" /></td></tr>
<tr><td>Font name:</td></tr>
<tr><td>
<select name="fontname">
<option value="Aquabase.ttf">Aquabase</option>
<option value="DejaVuSerif.ttf">DejaVu (Serif)</option>
<option value="handwriting.ttf">Handwriting</option>
<option value="JOURNAL.ttf">Journal</option>
<option value="KOMIKAX_.ttf">Komikax</option>
<option value="lcd.ttf">LCD</option>
<option value="scoreboard.ttf">Scoreboard</option>
<option value="scream.ttf">Scream</option>
<option value="typewriter.ttf">Typewriter</option>
</select>
</td></tr>
<tr><td>Font size:</td></tr>
<tr><td>
<select name="fontsize">
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="14">14</option>
<option value="16">16</option>
<option value="18">18</option>
<option value="20">20</option>
<option value="24">24</option>
<option value="26">26</option>
</select>
</td></tr>
<tr><td>Text Offset Left:</td></tr>
<tr><td><input type = "text" name="t_offl" value="" /></td></tr>
<tr><td>Text Offset Top:</td></tr>
<tr><td><input type = "text" name="t_offt" value="" /></td></tr>
<tr><td>Text Area Width:</td></tr>
<tr><td><input type = "text" name="t_boxw" value="" /></td></tr>
<tr><td>Image File:</td></tr>
<tr><td><input type = "file" name="imageurl" value="" /></td></tr>

<tr><td align="right"><input type = "submit" name="submit_invest" value="Send" /><input type="reset" /></td></tr>
</table>
</form>
EOF;
$title = "Add a New Image";
include ("base.php");
echo $html;
}

?>
